<template>
  <div id="shareTopSearch">
    <h1 class="con-right-title">
      活动列表
    </h1>
    <div class="search-box">
      <el-form
        ref="formInline"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <!-- 输入搜索部分 -->
        <el-form-item label="搜索" prop="activityName">
          <el-input
            clearable
            v-model="formInline.activityName"
            placeholder="请输入活动名称"
            size="small"
            class="numberInput"
          ></el-input>
        </el-form-item>
        <el-form-item label="活动状态" prop="activityStatus">
          <el-select
            v-model="formInline.activityStatus"
            filterable
            placeholder="请选择活动状态"
          >
            <el-option
              v-for="item in [
                { dictLabel: '全部', dictValue: '' },
                ...activeList
              ]"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动开始时间" prop="channelNum">
          <el-date-picker
            style="width:400px"
            v-model="formInline.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('formInline')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'adviserListTopSearch',
  msg: '顾问转介绍活动列表页-顶部搜索',
  props: {
    activeList: {
      type: Array,
      default() {
        return []
      }
    },
    formInline: {
      type: Object,
      default: function() {
        return {
          formInline: {
            time: [],
            activityName: '', //活动名称
            activityStatus: '', // 活动状态
            activityStartTimeStart: '',
            activityStartTimeEnd: ''
          }
        }
      }
    }
  },
  data() {
    return {
      rules: {
        type: {},
        collegeId: {},
        title: {}
      }
    }
  },
  mounted() {},
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['formInline'].resetFields()
      this.formInline.time = []
    }
  },
  watch: {
    'formInline.time': {
      handler(newV, oldV) {
        if (newV == null) {
          this.formInline.activityStartTimeStart = ''
          this.formInline.activityStartTimeEnd = ''
        } else {
          this.formInline.activityStartTimeStart = newV[0]
          this.formInline.activityStartTimeEnd = newV[1]
        }
      },
      immediate: true,
      deep: true
    }
  }
}
</script>
